{extend name="base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">课程评价</li>
                <li><a href="{:url('admin/dp/review_add')}">添加评价</a></li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table class="layui-table" lay-size="sm">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>课程名</th>
                                <th>评价人</th>
                                <th>评分</th>
                                <th>内容</th>
                                <th>时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        {foreach name="reviews" item="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.course_name}</td>
                                <td>{$vo.username}</td>
                                <td>{$vo.rating} 星</td>
                                <td>{$vo.content}</td>
                                <td>{:date('Y-m-d H:i', $vo.create_time)}</td>
                                <td>
                                    <a href="{:url('admin/dp/review_delete',['id'=>$vo.id])}" class="layui-btn layui-btn-sm ajax-delete">删除</a>
                                </td>
                            </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
layui.use(['layer'], function(){
    var $ = layui.jquery, layer = layui.layer;

    $('.ajax-delete').on('click', function(){
        var url = $(this).attr('href');
        layer.confirm('确定删除该评价？', function(index){
            $.get(url, function(res){
                if(res.code === 1){
                    location.reload();
                }
                layer.msg(res.msg);
            });
            layer.close(index);
        });
        return false;
    });
});
</script>
{/block}
